/***************************************************************************
 *            shortcuts.c
 *
 *  Fri Oct 10 00:19:09 2008
 *  Copyright  2008  Tiago Falcao
 *  <developer@tiagofalcao.com>
 ****************************************************************************/

/*
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Library General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor Boston, MA 02110-1301,  USA
 */
 
#include "shortcuts.h"

 //Listener do Teclado
void key_listener(unsigned char key,int x,int y){
	if(! objs->selected){							//CAMERA
		switch(key){
			case GLUT_KEY_ESC:					//Sai do programa
				exit(0);
			case '8':							//Rotaciona para cima
				cam_rot_phi (-1);break;
			case '2':							//Rotaciona para baixo
				cam_rot_phi (1);break;
			case '4':							//Rotaciona para esquerda
				cam_rot_theta (-1);break;
			case '6':							//Rotaciona para direita
				cam_rot_theta (1);break;
			case '+':							//Afasta Camera
				cam_zoom(1);break;
			case '-':							//Aproxima Camera
				cam_zoom(-1);break;
		}
		//Reconfigura Camera
		cam_setup();
	}else{										//OBJETO
		switch(key){
			case GLUT_KEY_ESC:					//Desmarca objeto
				objects_manager_unselect(objs);
				break;
			case '8':							//Rotaciona para cima
				object_rot_x(objs->selected,-1);break;
			case '2':							//Rotaciona para baixo
				object_rot_x(objs->selected,1);break;
			case '4':							//Rotaciona para esquerda
				object_rot_y(objs->selected,-1);break;
			case '6':							//Rotaciona para direita
				object_rot_y(objs->selected,1);break;
			case '9':							//Rotaciona anti-horario
				object_rot_z(objs->selected,1);break;
			case '3':							//Rotaciona horario
				object_rot_z(objs->selected,-1);break;
			case '+':							//Aumenta Tamanho
				object_size(objs->selected,1);break;
			case '-':							// Reduz Tamanho
				object_size(objs->selected,-1);break;
			case 'q':							// Scala x +
				object_scale_x(objs->selected,1);break;
			case 'a':							// Scala x -
				object_scale_x(objs->selected,-1);break;
			case 'w':							// Scala y +
				object_scale_y(objs->selected,1);break;
			case 's':							// Scala y -
				object_scale_y(objs->selected,-1);break;
			case 'e':							// Scala z +
				object_scale_z(objs->selected,1);break;
			case 'd':							// Scala z -
				object_scale_z(objs->selected,-1);break;
			case 'z':							// Modo
				objs->selected->mode=OBJ3D_MODE_WIRE;break;
			case 'x':							// Modo
				objs->selected->mode=OBJ3D_MODE_FILL;break;
			case 'c':							// Modo
				objs->selected->mode=OBJ3D_MODE_WIRE | OBJ3D_MODE_FILL;break;
			case 'v':							// Modo
				objs->selected->mode=OBJ3D_MODE_SMOOTH | OBJ3D_MODE_FILL;break;
			case 'b':							// Modo
				objs->selected->mode=OBJ3D_MODE_FACE;break;
			case 'n':							// Modo
				objs->selected->mode=OBJ3D_MODE_SMOOTH | OBJ3D_MODE_FACE | OBJ3D_MODE_FILL;break;
		}
	}//ELSE

	//Redisplay
	glutPostRedisplay();
}

//Listener de Teclas Especiais
void special_key_listener(int key,int x,int y){
	if(! objs->selected){							//CAMERA
		switch(key){
			case GLUT_KEY_F2:					//Seleciona Objeto Anterior
				objects_manager_select_prev(objs);
				break;
			case GLUT_KEY_F3:					//Seleciona Proximo Objeto
				objects_manager_select_next(objs);
				break;
			case GLUT_KEY_UP:					//Move a Camera para "Cima"
				cam_trans_y (1);break;
			case GLUT_KEY_DOWN:					//Move a Camera para "Baixo"
				cam_trans_y (-1);break;
			case GLUT_KEY_LEFT:					//Move a Camera para "Esquerda"
				cam_trans_x (-1);break;
			case GLUT_KEY_RIGHT:				//Move a Camera para "Direita"
				cam_trans_x (1);break;
			case GLUT_KEY_PAGE_UP:				//Move a Camera para "Tras"
				cam_trans_z (-1);break;
			case GLUT_KEY_PAGE_DOWN:			//Move a Camera para "Frente"
				cam_trans_z (1);break;
		}
		//Reconfigura Camera
		cam_setup();
	}else{										//OBJETO
		switch(key){
			case GLUT_KEY_F2:					//Seleciona Objeto Anterior
				objects_manager_select_prev(objs);
				break;
			case GLUT_KEY_F3:					//Seleciona Proximo Objeto
				objects_manager_select_next(objs);
				break;
			case GLUT_KEY_END:					//Deleta Objeto
				objects_manager_delete_selected(objs);
				break;
			case GLUT_KEY_UP:					//Move o Objeto para "Cima"
				object_trans_y(objs->selected,1);break;
			case GLUT_KEY_DOWN:					//Move o Objeto para "Baixo"
				object_trans_y(objs->selected,-1);break;
			case GLUT_KEY_LEFT:					//Move o Objeto para "Esquerda"
				object_trans_x(objs->selected,-1);break;
			case GLUT_KEY_RIGHT:				//Move o Objeto para "Direita"
				object_trans_x(objs->selected,1);break;
			case GLUT_KEY_PAGE_UP:				//Move o Objeto para "Tras"
				object_trans_z(objs->selected,-1);break;
			case GLUT_KEY_PAGE_DOWN:			//Move o Objeto para "Frente"
				object_trans_z(objs->selected,1);break;
		}
	}
	//Redisplay
	glutPostRedisplay();
}
